// pages/profile/index.ts
Page({
  data: {
    userInfo: {},
  },
  onShow() {
    this.getUserInfo()
  },
  async getUserInfo() {
    const { data } = await wx.http.get('/userInfo')
    this.setData({ userInfo: data })
  },
  async updateNickName(e) {
    await wx.http.put('/userInfo', { nickName: e.detail.value })
  },
  async updateAvatar(e) {
    const res = await wx.http.upload('/upload', {
      name: 'file',
      filePath: e.detail.avatarUrl,
      formData: {
        type: 'avatar',
      },
    })
    this.setData({
      'userInfo.avatar': res.data.url,
    })
  },
})
